﻿@using KPIS.GERP.Models.ICM
@model IEnumerable<KPIS.GERP.Models.ICM.MovementDtl>

@{
    ViewBag.Title = "ระบบควบคุมและจำหน่ายพัสดุ";
    ViewBag.Descr = "โอนย้าย";

    int intMovementId = ViewBag.MovementId;
}

@using (Html.BeginForm("DeleteAllMovementDtl", "Movement", FormMethod.Post))
{
    @Html.AntiForgeryToken()
    <div class="row-fluid">
        <div class="block-button-menu-above">
            @Html.ButtonViewAll()
            @Html.ActionLink("เพิ่ม", "CreateMovementDtl", new { MovementId = intMovementId }
              , new { @class = "btn btn-small btn-success button-standard-width", role = "button" })
            @Html.ButtonDeleteAll()
           <button type="button" onclick="window.location.href ='@Url.Action("MovementDtlsReport", new { MovementId = intMovementId })'"
            class="btn button-standard-width btn-small btn-blue" 
            data-rel="tooltip" role="button"  >
            <i class="icon-file bigger-120"></i>&nbsp;&nbsp;รายงานใบส่งคืนพัสดุ
           </button>
        </div>

       @Html.ValidationSummary(true, "", new { @class = "alert alert-error" })

       <div class="row-fluid">
        <div class="table-header span12">
            <div class="span10">
               โอนย้าย
            </div>
            <div class="btn-group pull-right">
                <button data-toggle="dropdown" class="btn btn-small btn-primary dropdown-toggle">
                    Export
                    <i class="icon-angle-down icon-on-right"></i>
                </button>

                <ul class="dropdown-menu dropdown-danger" style="min-width: 80px;">
                    <li>
                        <a href="#"><i class="icon-file bigger-125"></i>  Word</a>
                    </li>

                    <li>
                        <a href="#"><i class="icon-table bigger-125"></i>  Excel</a>
                    </li>

                    <li>
                        <a href="#"><i class="icon-file-alt bigger-125"></i>  PDF</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>

    <table id="table" class="table table-striped table-bordered table-hover"
        aria-describedby="table_info">
        <thead>
            <tr>
                <th class="center" style="width: 50px;">
                    <label>
                        <input type="checkbox" />
                        <span class="lbl"></span>
                    </label>
                </th>
                <th>
                    รายการพัสดุ 
                </th>
                <th>
                    หมายเลขซีเรียล 
                </th>
                <th>
                    จำนวนที่ต้องการโอนย้าย 
                </th>
               <th>&nbsp;</th>
            </tr>
        </thead>
    

       <tbody>
            @foreach (var m in Model)
            {
                <tr>
                    <td class="center">
                        <label>
                            <input type="checkbox" name="deleteIds" value="@(m.MovementDtlId)" />
                            <span class="lbl"></span>
                        </label>
                    </td>

                    <td>@Html.DisplayFor(modelItem => m.Asset.AssetName)</td>
                    <td>@Html.DisplayFor(modelItem => m.Asset.SerialNumber)</td>
                    <td>@Html.DisplayFor(modelItem => m.MoveQty)</td>
                    <td class="td-actions">
                        <div class="hidden-phone visible-desktop btn-group">
                           @* <a id = "cmdUpdateSub" href="/Movement/EditMovementDtl/@(m.MovementDtlId)" role="button"
                                class="btn btn-success btn-mini" data-dialog-id = "aboutDialog" data-dialog-title = "แก้ไข">
                                <i class="icon-edit bigger-120"></i>
                            </a>*@

                            @Html.ButtonDelete(new { id = m.MovementDtlId, m.MovementId }, true, "DeleteMovementDtl")
                        </div>

                        <div class="hidden-desktop visible-phone">
                            <div class="inline position-relative">
                                <button class="btn btn-minier btn-yellow dropdown-toggle" data-toggle="dropdown">
                                    <i class="icon-caret-down icon-only bigger-120"></i>
                                </button>

                                <ul class="dropdown-menu dropdown-icon-only dropdown-yellow pull-right dropdown-caret dropdown-close">
                                   @* <li>
                                        <a id="cmdUpdateSubMini" href="/Movement/EditMovementDtl/@(m.MovementDtlId)" class="tooltip-success" data-rel="tooltip" title="แก้ไข" data-placement="left">
                                            <span class="green">
                                                <i class="icon-edit"></i>
                                            </span>
                                        </a>
                                    </li>*@

                                    <li>
                                        <a href="/Movement/DeleteMovementDtl/@(m.MovementDtlId)" class="tooltip-error" data-rel="tooltip" title="ลบ" data-placement="left">
                                            <span class="red">
                                                <i class="icon-trash"></i>
                                            </span>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </td>
                </tr>
            }
        </tbody>
    </table>
  </div>
    
}

@section scripts {
    
	<script type="text/javascript">
	    $(function () {
	        var oTable1 = $('#table').dataTable({
	            "aoColumns": [
                    { "bSortable": false },
                    null,
                    null,
                    { "bSortable": false }
	            ]
	        });

	        $('table th input:checkbox').on('click', function () {
	            var that = this;
	            $(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function () {
				    this.checked = that.checked;
				    $(this).closest('tr').toggleClass('selected');
				});

	        });

	        $('[data-rel=tooltip]').tooltip();

	        $("form").submit(function () {
	            var currentForm = this;
	            bootbox.confirm(function (result) {
	                var _result = result;
	                if (result) {
	                    $.ajax({
	                        url: "DeleteAllMovementDtl",
	                        type: "post",
	                        dataType: "json",
	                        data: $(currentForm).serialize(),
	                        success: function (result) {
	                            if (result.success) {
	                                location.reload();
	                            } else {
	                            }
	                        }
	                    });
	                }
	            })
	            return false;
	        });
	    })



   </script>
}